<template>
  <button type="button" class="lineBtn" @click="upload_zip" style="width: 100%; margin-left: 0">下载字符串</button>
</template>

<script setup>
import UploadZip from '@/pages/Acomponents/UploadZip/UploadZip.vue';

const fileUrl = '/static/归档.zip'; // 放在static文件夹下

const upload_zip = () => {
  // GET 请求示例
  uni.request({
    url: 'http://172.16.9.205:3000/downcode', // 请求的接口地址
    method: 'GET',
    data: {
      // id: 1,
      // page: 1
    },
    header: {
      // 'content-type': 'application/json'
    },
    success: (res) => {
      console.log('请求成功：', res.data);

      let content = res.data.content;
      // const decodedText = uni.base64ToArrayBuffer(content); // 使用 uni-app 提供的 base64 解码方法
      // const decoder = new TextDecoder('utf-8'); // 将 ArrayBuffer 转换为字符串

      const decodedText = decodeURIComponent(escape(atob(content)));
      console.log('解码后的内容：', decodedText);

      // const decodedText = decodeURIComponent(escape(atob(content)));
      // const text = decoder.decode(decodedText);
      // console.log('decodedText：', text);
    },
    fail: (err) => {
      console.log('请求失败：', err);
    },
    complete: () => {
      console.log('请求完成');
    }
  });
};
</script>

<style scoped lang="scss">
.lineBtn {
  display: block;
  width: 80%;
  margin-left: 10%;
  padding: 0;
  height: 50px;
  border-radius: 100px;
  line-height: 50px;
  background: #1e9fff;
  color: #ffffff;
  border: none;
  font-size: 16px;
}
</style>
